"""
1-7月各街道矛盾纠纷扇形图、圆环图
"""

import matplotlib.pyplot as plt
import numpy as np

months = ["一月", "二月", "三月", "四月", "五月", "六月", "七月"]
data = [
    [81, 81, 76, 77, 138, 163, 124],  # 凌水
    [108, 106, 93, 86, 91, 56, 108],  # 七贤岭
    [26, 25, 25, 26, 86, 66, 93],  # 龙王塘
]
labels = ["凌水", "七贤岭", "龙王塘"]
colors = ["blue", "red", "green", "yellow", "purple"]
sum_data = [sum(x) for x in data]

# 圆环图
# paches, texts, autotexts = plt.pie(
#     sum_data,
#     radius=1.5,
#     wedgeprops={"width": 0.7},
#     labels=labels,
#     colors=colors,
#     autopct="%1.1f%%",
#     startangle=90,
#     pctdistance=0.8,
# )

# 饼图
paches, texts, autotexts = plt.pie(
    sum_data,
    radius=1.5,
    labels=labels,
    colors=colors,
    autopct="%1.1f%%",
    startangle=90,
    explode=[0.1, 0, 0],  # 突出某个扇区
)


# 设置中文用楷体
plt.rcParams["font.sans-serif"] = ["KaiTi"]

# plt.legend(loc="upper left")
plt.grid(True)
plt.title(f"1-{len(months)}月街道矛盾纠纷排查量对比")

# 可以进一步自定义文本和扇区
for text in texts:
    text.set_color("black")  # 将文本颜色设置为黑色
    text.set_fontsize(12)  # 设置文本大小

for text in autotexts:
    text.set_color("white")  # 将自动生成的文本颜色设置为白色
    text.set_fontsize(8)  # 设置文本大小

for patch in paches:
    patch.set_edgecolor("black")  # 将扇区边缘颜色设置为黑色

plt.axis("equal")  # 保持饼图的圆形plt.show()

# 显示图形
plt.show()
